import 'package:flutter/cupertino.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:my_flutter/BasicComponents/InputAndForm/FocusTestRoute.dart';
import 'package:my_flutter/StudyLayout/StudyLinearLayout.dart';

import '../BasicComponents/Image/StudyImage.dart';
import '../BasicComponents/InputAndForm/FormTestRoute.dart';
import '../BasicComponents/InputAndForm/InputAndForm.dart';
import '../BasicComponents/button/StudyButton.dart';
import '../BasicComponents/switchAndCheckBox/SwitchAndCheckBox.dart';
import '../BasicComponents/test/TextAndStyle.dart';
import '../BasicComponents/testProgress/ProgressBarTestRoute.dart';
import '../StudyLayout/StudyFlexLayout.dart';
import '../StudyLayout/StudyFlowLayout.dart';
import '../StudyLayout/StudyRelativeLayout.dart';
import '../StudyLayout/StudyStackLayout.dart';

class RouteOutside {
  final Map<String, WidgetBuilder> _routes = <String, WidgetBuilder>{};
  final _listData = <String, String>{};

  RouteOutside() {
    // initList();
  }

  void init() {
    initRoute();
    initList();
  }

  void initRoute() {
    _routes['test_and_style'] = (context) => TextAndStyle();
    _routes['study_button'] = (context) => const StudyButton();
    _routes['study_image'] = (context) => const StudyImage();
    _routes['switch_and_checkBox'] = (context) => const SwitchAndCheckBox();
    _routes['input_and_form'] = (context) => InputAndForm();
    _routes['focus_test_route'] = (context) => const FocusTestRoute();
    _routes['form_test_route'] = (context) => const FormTestRoute();
    _routes['progressBar_test_route'] = (context) => ProgressBarTestRoute();
    _routes['study_linear_layout'] = (context) => StudyLinearLayout();
    _routes['study_flex_layout'] = (context) => StudyFlexLayout();
    _routes['study_flow_layout'] = (context) => StudyFlowLayout();
    _routes['study_stack_layout'] = (context) => StudyStackLayout();
    _routes['study_Relative_layout'] = (context) => StudyRelativeLayout();
  }

  void initList() {
    _listData['文本及样式'] = 'test_and_style';
    _listData['Button'] = 'study_button';
    _listData['图片及ICON'] = 'study_image';
    _listData['单选开关和复选框'] = 'switch_and_checkBox';
    _listData['输入框及表单'] = 'input_and_form';
    _listData['Text Field'] = 'form_test_route';
    _listData['进度指示器'] = 'progressBar_test_route';
    _listData['线性布局'] = 'study_linear_layout';
    _listData['弹性布局'] = 'study_flex_layout';
    _listData['流式布局'] = 'study_flow_layout';
    _listData['层叠布局'] = 'study_stack_layout';
    _listData['对齐和相对布局'] = 'study_Relative_layout';
  }

  Iterable<String>? getRouteKeys() {
    Fluttertoast.showToast(msg: "验证成功", toastLength: Toast.LENGTH_SHORT);
    if (verifyRoute()) return null;
    return _routes.keys;
  }

  Iterable<WidgetBuilder>? getRouteValues() {
    if (verifyRoute()) return null;
    return _routes.values;
  }

  bool verifyRoute() {
    if (_routes.isEmpty) {
      Fluttertoast.showToast(
          msg: "routes isEmpty", toastLength: Toast.LENGTH_SHORT);
      return true;
    }
    return false;
  }

  bool verifyList() {
    if (_listData.isEmpty) {
      Fluttertoast.showToast(
          msg: "list data isEmpty", toastLength: Toast.LENGTH_SHORT);
      return true;
    }
    return false;
  }

  int? size() {
    if (verifyRoute()) return null;
    return _routes.length;
  }

  Map<String, WidgetBuilder> getRoute() {
    if (verifyRoute()) return const <String, WidgetBuilder>{};
    return _routes;
  }

  Map<String, String> getList() {
    if (verifyList()) return <String, String>{};
    return _listData;
  }

  List<String>? getListKeys() {
    if (verifyList()) return null;
    var items = <String>[];
    for (var element in _listData.keys) {
      items.add(element);
    }
    return items;
  }

  List<String>? getListValues() {
    if (verifyList()) return null;
    var items = <String>[];
    for (var element in _listData.values) {
      items.add(element);
    }
    return items;
  }
}
